<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-incomeInfo-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">考核年月：</label>
				<div class="col-sm-8">
					<input id="incMonth" name="incMonth" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">考核周期：</label>
				<div class="col-sm-8 form-inline select-month">
							<input type="text" class="time-input form-control" id="startTime" placeholder="开始日期" name="params[beginTime]"/>
							<span class="form-control text-center" style="border:0;">至</span>
							<input type="text" class="time-input form-control" id="endTime" placeholder="结束日期" name="params[endTime]"/>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">说明：</label>
				<div class="col-sm-8">
					<input id="incNote" name="incNote" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<select id="incStat" class="form-control m-b" th:with="type=${@dict.getType('pm_do_status')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">项目名称：</label>
				<div class="col-sm-8">
					<select id="proId" name="proId" class="form-control m-b" th:with="type=${@ProInfoServiceImpl.selectProsBySta('0')}">
						<option th:each="dict : ${type}" th:text="${dict.proName}" th:value="${dict.proId}"></option>
					</select>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "pm/incomeInfo"
		$("#form-incomeInfo-add").validate({
			rules:{
				incMonth:{
        			required:true
        		},
        		proId:{
        			required:true
        		}
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            add();
	        }
	    }
		
		// laydate 时间控件绑定
		layui.use('laydate', function() {
		    var laydate = layui.laydate;
		    var startDate = laydate.render({
		        elem: '#startTime',
		        max: $('#endTime').val(),
		        theme: 'default',
		        trigger: 'click',
		        done: function(value, date) {
		            // 结束时间大于开始时间
		            if (value !== '') {
		                endDate.config.min.year = date.year;
		                endDate.config.min.month = date.month - 1;
		                endDate.config.min.date = date.date;
		            } else {
		                endDate.config.min.year = '';
		                endDate.config.min.month = '';
		                endDate.config.min.date = '';
		            }
		        }
		    });
		    var endDate = laydate.render({
		        elem: '#endTime',
		        min: $('#startTime').val(),
		        theme: 'default',
		        trigger: 'click',
		        done: function(value, date) {
		            // 开始时间小于结束时间
		            if (value !== '') {
		                startDate.config.max.year = date.year;
		                startDate.config.max.month = date.month - 1;
		                startDate.config.max.date = date.date;
		            } else {
		                startDate.config.max.year = '';
		                startDate.config.max.month = '';
		                startDate.config.max.date = '';
		            }
		        }
		    });
		});
	
		function add() {
			var incMonth = $("input[name='incMonth']").val();
        	var incNote = $("input[name='incNote']").val();
        	var proId = $("#proId option:selected").val();
        	var incStdt = $("#startTime").val();
        	var incEddt = $("#endTime").val();
        	var incStat = $("#incStat option:selected").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "pm/incomeInfo/add",
        		data : {
        			"incMonth": incMonth,
        			"incNote": incNote,
        			"proId": proId,
        			"incStdt": incStdt,
        			"incEddt": incEddt,
        			"incStat": incStat
        		},
        		async : true,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }
	</script>
</body>
</html>
